import { macro, loader, SpriteFrame, find, director, instantiate, game } from "cc";


export class Utils {

    PlatformUtils: any;

    random(e, r) {
        switch (arguments.length) {
            case 1:
                return Math.random() * e + 1;
            case 2:
                return Math.random() * (r - e + 1) + e;   
            default:
                return 0;
        }
    }



    trim(e) {
        if (e) return e.replace(/(^\s*)|(\s*$)/g, "");
    }


    mergeTable(e, r) {
        for (var n in r)
            if (r.hasOwnProperty(n)) {
                var t = r[n];
                e[n] ? (e[n] += t) : (e[n] = t);
            }
        return e;
    }

    getAppName(e, r) {
        if (((r = r || 5), e.length <= r)) return e;
        for (var n = "", t = 0; t < r - 1; t++) {
            n += e[t];
        }
        return (n += "...");
    }
    calcRadian(e, r) {
        var n = r.x - e.x,
            t = r.y - e.y;
        return 0 == n ? (t >= 0 ? 0 : 1) : Math.atan2(n, t);
    }
    calcAngle(e, r) {
        return this.calcRadian(e, r) * macro.DEG;
    }
    getRadianByAngle(e) {
        return e / macro.DEG;
    }
    getSpeedByAngle(e, r) {
        var n = this.getRadianByAngle(e);
        return this.getSpeedByRadian(n, r);
    }
    getSpeedByRadian(e, r) {
        return { speedX: r * Math.cos(e), speedY: r * Math.sin(e) };
    }
    getSpeedByPosition(e, r, n) {
        var t = this.calcAngle(r, n);
        return (t = 90 - t), this.getSpeedByAngle(t, e);
    }
    getDistancePow(e, r) {
        var n = r.x - e.x,
            t = r.y - e.y;
        return Math.pow(n, 2) + Math.pow(t, 2);
    }
    getDistance(e, r) {
        return Math.sqrt(this.getDistancePow(e, r));
    }
    isInRange(e, r, n) {
        var t = r.x - e.x,
            s = r.y - e.y;
        return Math.pow(t, 2) + Math.pow(s, 2) <= n * n;
    }
    loadSpriteTexture(e, r, n) {
        loader.loadRes(r, SpriteFrame, function (r, t) {
            (e.spriteFrame = t), n && n();
        });
    }
    encodeNumber(e) {
        if (null == e || void 0 == e || e <= 0) return e;
        var r = this.random(1, 5),
            n = this.random(1, 9);
        return (e *= r), (e += n), (e *= 10), (e += r), (e *= 10), (e += n);
    }
    decodeNumber(e) {
        if (null == e || void 0 == e || e < 100) return e;
        var r = e % 10;
        e /= 10;
        var n = (e = Math.floor(e)) % 10;
        return (e /= 10), (e = Math.floor(e)), (e -= r), (e /= n), Math.floor(e);
    }
    getUnxTimestamp() {
        return this.PlatformUtils || (this.PlatformUtils = find("PlatformUtils").getComponent("PlatformUtils")), this.PlatformUtils.getServerTime();
    }
    setClipboardData(e) {
        return this.PlatformUtils || (this.PlatformUtils = find("PlatformUtils").getComponent("PlatformUtils")), this.PlatformUtils.setClipboardData(e);
    }
    getClipboardData(e) {
        return this.PlatformUtils || (this.PlatformUtils = find("PlatformUtils").getComponent("PlatformUtils")), this.PlatformUtils.getClipboardData(e);
    }
    getTimerStr(e) {

    }
    getDateNumber() {

    }
    isBetweenHours(e, r) {

    }
    loadSceneWithFade(e, r, n, t) {

    }
    showBlackMask(e, r, n, t, s) { }

    getNumStrWithUnit(e) {

    }
    showTip(e) {

    }
    loadIconTexture(e, r, n) {

    }
    loadExtraRewardIcon(e, r) {

    }
    getStrRealLength(e) {
        for (var r = 0, n = e.length, t = -1, s = 0; s < n; s++) r += (t = e.charCodeAt(s)) >= 0 && t <= 128 ? 1 : 2;
        return r;
    }
    showDescTip(e, r) {

    }
    addTouchDescTip(e) {

    }
    loadTextureByUrl(e, r, n) {

    }
    zipData(e, r) {

    }
    unzipData(e, r) {

    }
}